﻿using UnityEngine;
using System.Collections;
using Configs;

public class IUnitObject : IWorldObject
{
    private ModuleManager modManager = null;

    private readonly ConfUnitObject confUnitObject = null;

    public IUnitObject(IStage stage, ConfUnitObject confUnitObject) : base(stage)
    {
        OwnerObj owner = GetSelfOwnerObj();

        this.confUnitObject = confUnitObject;

        prefabName = confUnitObject.model;

        modManager = new ModuleManager(owner);

        GetModule().GetOrNew<ModAction>();
        GetModule().GetOrNew<ModAttr>();
        GetModule().GetOrNew<ModDamage>();
    }

    public override void Destroy()
    {
        base.Destroy();

        GetModule().RemoveAllNow();
    }

    /// <summary>
    /// module管理器
    /// </summary>
    /// <returns></returns>
    public ModuleManager GetModule()
    {
        return modManager;
    }

    /// <summary>
    /// 更新
    /// </summary>
    /// <param name="time"></param>
    public override void Update(float deltaTime)
    {
        base.Update(deltaTime);

        modManager.Update(deltaTime);
    }

    public bool IsDead()
    {
        ModAttr modAttr = GetModule().Get<ModAttr>();
        if (null != modAttr)
        {
            return modAttr.IsDead();
        }
        else
        {
            return true;
        }
    }

}
